const deepReport = require('../report/deepReport')
const UI = require("../style/UI.js")

function deepReportTransition(obj) {
  let report = new deepReport(obj)
  let result = {}

  result.weight = {
    value: report.weight,
    unit: 'kg'
  }
  result.bodyfat = {
    value: report.bodyfat,
    unit: '%'
  }
  result.muscle = {
    value: report.muscle,
    unit: '%'
  }
  result.weightControls = {
    bodyfatWeight: report.bodyfatMass,
    weightControl: report.controls.weightControl,
    fatControl: report.controls.fatControl,
    muscleControl: report.controls.muscleControl,
    unit: 'kg'
  }
  let muscleList = ["肌肉比率低", "肌肉比率标准", "肌肉比率高"]
  result.muscleType = {
    muscleLevelString: muscleList[report.muscleLevel],
    muscleLevel: report.muscleLevel,
    muscleLevelList: muscleList,
    weight: {
      value: report.weight,
      unit: 'kg'
    },
    muscleMass: {
      value: report.muscleMass,
      unit: 'kg'
    },
    muscle: {
      value: report.muscle,
      unit: '%'
    }
  }
  result.nutrition = {
    bodyfatColor: report.nutrition.bodyfatColor,
    bodyfatLevel: report.nutrition.bodyfatLevel,
    bodyfatString: '体脂肪',
    mineralsaltColor: report.nutrition.boneColor,
    mineralsaltLevel: report.nutrition.boneLevel,
    mineralsaltString: '无机盐',
    proteinColor: report.nutrition.proteinColor,
    proteinLevel: report.nutrition.proteinLevel,
    proteinString: '蛋白质'
  }
  result.fat = {
    bmiItem: report.bmiItem,
    bodyfatItem: report.bodyfatItem
  }

  let bmrLevel = report.bmrLevel
  let bmrColorList = [UI.color.report_lower, UI.color.report_stand]
  let bmrLevelList = ["低", "正常"]
  
  let bodyAgeLevel = report.bodyAgeLevel
  let bodyAgeLevelList = ["正常", "高"]
  let bodyAgeColorList = [UI.color.report_stand, UI.color.report_higher]

  result.energy = {
    bmr: {
      bmrLevelList,
      bmrLevel,
      bmrLevelString: bmrLevelList[bmrLevel],
      bmrLevelColor: bmrColorList[bmrLevel],
      bmrColorList
    },
    bodyAge: {
      bodyAgeLevel,
      bodyAgeLevelList,
      bodyAgeLevelString: bodyAgeLevelList[bodyAgeLevel],
      bodyAgeLevelColor: bodyAgeColorList[bodyAgeLevel],
      bodyAgeColorList
    }
  }

  let visfatList = ["暂无肥胖性脂肪肝风险。", "存在患上脂肪肝的风险。", "存在轻度脂肪肝的风险。", "存在中度脂肪肝的风险。", "存在重度脂肪肝的风险。"]
  let visfatValue = report.measure.visfat
  let visfatLevel = 0
  if (visfatValue <= 7) {
    visfatLevel = 0
  } else if (visfatValue <= 9) {
    visfatLevel = 1
  } else if (visfatValue <= 12) {
    visfatLevel = 2
  } else if (visfatValue <= 14) {
    visfatLevel = 3
  } else {
    visfatLevel = 4
  }
  result.visfat = {
    visfatList,
    visfatLevel,
    visfatString: visfatList[visfatLevel]
  }

  result.bodyShapeItem = report.bodyShapeItem

  let scoreLevelList = ['糟糕', '一般', '良好', '优秀']
  let scoreLevel = 0
  if (report.score > 90) {
    scoreLevel = 3
  } else if (report.score > 80) {
    scoreLevel = 2
  } else if (report.score >= 60) {
    scoreLevel = 1
  } else {
    scoreLevel = 0
  }

  result.score = {
    value: report.score,
    scoreLevelList,
    level: scoreLevel,
    scoreString: scoreLevelList[scoreLevel]
  }
  return result
}




module.exports = deepReportTransition